package com.business.activiti.service;

import com.business.activiti.mapper.auto.AppealInfoMapper;
import com.business.activiti.model.auto.AppealInfo;
import com.business.activiti.model.auto.AppealInfoExample;
import com.business.system.common.base.BaseService;
import com.business.system.common.support.Convert;
import com.business.system.model.custom.Tablepar;
import com.business.system.util.SnowflakeIdWorker;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 诉求信息 AppealInfoService
 * @Title: AppealInfoService.java 
 * @Package com.business.activiti.service 
 * @author LuJingyuan_自动生成
 * @email 674326842@qq.com
 * @date 2020-11-18 14:12:53  
 **/
@Service
public class AppealInfoService implements BaseService<AppealInfo, AppealInfoExample>{
	@Autowired
	private AppealInfoMapper appealInfoMapper;
	
      	   	      	      	      	      	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<AppealInfo> list(Tablepar tablepar,String name){
	        AppealInfoExample testExample=new AppealInfoExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
				switch (name){
					case "处理中":
						testExample.createCriteria().andStatusEqualTo(0);
						break;
					case "已处理":
						testExample.createCriteria().andStatusEqualTo(1);
						break;
				}

	        }

	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<AppealInfo> list= appealInfoMapper.selectByExample(testExample);
	        PageInfo<AppealInfo> pageInfo = new PageInfo<AppealInfo>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista=Convert.toListStrArray(ids);
			AppealInfoExample example=new AppealInfoExample();
			example.createCriteria().andIdIn(lista);
			return appealInfoMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public AppealInfo selectByPrimaryKey(String id) {
				
			return appealInfoMapper.selectByPrimaryKey(id);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(AppealInfo record) {
		return appealInfoMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(AppealInfo record) {
				
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
			
				
		return appealInfoMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(AppealInfo record, AppealInfoExample example) {
		
		return appealInfoMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(AppealInfo record, AppealInfoExample example) {
		
		return appealInfoMapper.updateByExample(record, example);
	}

	@Override
	public List<AppealInfo> selectByExample(AppealInfoExample example) {
		
		return appealInfoMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(AppealInfoExample example) {
		
		return appealInfoMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(AppealInfoExample example) {
		
		return appealInfoMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param appealInfo
	 * @return
	 */
	public int checkNameUnique(AppealInfo appealInfo){
		AppealInfoExample example=new AppealInfoExample();
		example.createCriteria().andAppealTypeIdEqualTo(appealInfo.getAppealTypeId());
		List<AppealInfo> list=appealInfoMapper.selectByExample(example);
		return list.size();
	}
	public List<AppealInfo> selectByMap(Map<String,String> map){
		return this.appealInfoMapper.selectByMap(map);
	}

	public AppealInfo selectOneByProcessInstance(String processInstanceId){
		return this.appealInfoMapper.selectOneByProcessInstance(processInstanceId);
	}

}
